﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace WebUI.pub
{
    public partial class pub_Left : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                bindTreeView();
            }
        }

        //为树型控件绑定数据
        private void bindTreeView()
        {
            if (Request.QueryString["user"] != null)
            {
                IList<Model.Favorite> list = BLL.Favorite.GetTopFavorite(BLL.UserInfo.GetUserInfo(Request.QueryString["user"].ToString()).UID);


                if (list != null)
                {

                    foreach (Model.Favorite modfav in list)
                    {
                        TreeNode node = new TreeNode(modfav.FName, modfav.FID.ToString(), "", "pub_Contents.aspx?node=" + modfav.FID.ToString(), "content");
                        createChildNode(node);
                        this.tvFavorite.Nodes.Add(node);
                    }
                }
            }
        }
        //使用递归绑定树型数据
        private void createChildNode(TreeNode node)
        {
            IList<Model.Favorite> childlist = BLL.Favorite.GetChildFavorite(Convert.ToInt32(node.Value));
            if (childlist != null)
            {

                foreach (Model.Favorite modfav in childlist)
                {
                    TreeNode childnode = new TreeNode(modfav.FName, modfav.FID.ToString(), "", "pub_Contents.aspx?node=" + modfav.FID.ToString(), "content");
                    createChildNode(childnode);
                    node.ChildNodes.Add(childnode);
                }
            }
        }
    }
}
